<?php
if(!defined('APP_NAME')) die('APP_NAME NO DEFINED!');
class C39{
	public static function run(){
		//1.设置常量
		self::_set_const();
		//2.创建文件夹
		self::_create_dir();
		//3.载入框架必须文件
		self::_load_file();
		//4.执行应用类的run
		Application::run();
	}


	private static function _set_const(){
		// F:\wamp\www\c390822/frame-project\C39\C39.php
		// echo __FILE__;
		$path = str_replace('\\', '/', __FILE__);
		//定义框架根路径
		//F:/wamp/www/c39/0822/frame-project/C39
		//定义项目类名称
		define('OBJ_NAME',__CLASS__);
		define('C39_PATH', dirname($path));
		//定义数据文件路径
		define('DATA_PATH', C39_PATH . '/Data');
		define('FONT_PATH', DATA_PATH . '/Font');
		//定义扩展路径
		define('EXTENDS_PATH', C39_PATH . '/Extends');
		//定义扩展里面的工具路径
		define('TOOL_PATH', EXTENDS_PATH . '/Tool');
		//定义框架Config路径
		define('CONFIG_PATH', C39_PATH . '/Config');
		//定义框架Lib路径
		define('LIB_PATH', C39_PATH . '/Lib');
		//定义框架Core路径
		define('CORE_PATH', LIB_PATH . '/Core');
		//定义框架Function路径
		define('FUNCTION_PATH', LIB_PATH . '/Function');


		//定义项目根路径
		//F:/wamp/www/c39/0822/frame-project
		define('ROOT_PATH', dirname(C39_PATH));
		//定义应用根路径
		define('APP_PATH', ROOT_PATH . '/' . APP_NAME);
		//定义应用的配置路径
		define('APP_CONFIG_PATH', APP_PATH . '/Config');
		//定义应用的模板路径
		define('APP_TPL_PATH', APP_PATH . '/Tpl');

		//用户应用临时目录
		define('APP_TEMP_PATH', APP_PATH . '/Temp');
		//用户应用编译目录
		define('APP_COMPILE_PATH', APP_PATH . '/Temp/Compile');
		//用户应用缓存目录
		define('APP_CACHE_PATH', APP_PATH . '/Temp/Cache');

		define('APP_PUBLIC_PATH', APP_TPL_PATH . '/Public');
		//定义应用的控制路径
		define('APP_CONTROL_PATH', APP_PATH . '/Control');

		define('IS_POST', $_SERVER['REQUEST_METHOD'] == 'POST' ? true : false);

		// define('IS_AJAX',isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false);

		if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){
			define('IS_AJAX', true);
		}else{
			define('IS_AJAX', false);
		}

	}

	/**
	 * [_create_dir 创建应用文件夹]
	 * @return [type] [description]
	 */
	private static function _create_dir(){
		$dirArr = array(
			APP_CONFIG_PATH,
			APP_TPL_PATH,
			APP_PUBLIC_PATH,
			APP_CONTROL_PATH,
			APP_COMPILE_PATH,
			APP_CACHE_PATH
			);
		foreach ($dirArr as $v) {
			is_dir($v) || mkdir($v,0777,true);
		}
	}

	/**
	 * [_load_file 加载框架必须文件]
	 * @return [type] [description]
	 */
	private static function _load_file(){
		$arr = array(
			FUNCTION_PATH . '/function.php',
			DATA_PATH . '/smarty/Smarty.class.php',
			CORE_PATH . '/SmartyView.class.php',
			CORE_PATH . '/Control.class.php',
			CORE_PATH . '/Application.class.php',

			);
		foreach ($arr as $v) {
			require_once $v;
		}
	}

}

C39::run();

?>